<!doctype html>
<html>
 <head>
  <meta charset="UTF-8"></meta>
  <title>找回密码</title>
  <link rel="stylesheet" href="/static/layui/css/layui.css"></link>
  <script type="text/javascript" src="/static/fsLayui/plugins/jquery/jquery.min.js"></script>
 </head>
<body style="height: 300px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>找回密码</legend>
</fieldset>
	<form class="layui-form" action="/user/register" method="post" style="text-align: center;">
		<div class="layui-form-item" style="margin-bottom: 5px;">
			<label class="layui-form-label">邮&nbsp;&nbsp;箱</label>
			<div class="layui-input-inline">
				<input type="text" name="email" required="" id="email"
					   lay-verify="email" placeholder="请输入注册时填写的邮箱" autocomplete="off"
					   class="layui-input" style="width: 280px;" />
			</div>
		</div>
		<div class="layui-form-item" style="margin-bottom: 5px;text-align: left">
			<label class="layui-form-label">验&nbsp;证&nbsp;码</label>
				<input id="yzm" type="text" name="yzm" autocomplete="off" placeholder="验证码"
					   class="layui-input" style="width: 80px;display: inline-block;margin-right: 20px" />
					<button id="yzmbtn" lay-submit="" lay-filter="sendEmail" class="layui-btn layui-btn-normal">获取验证码</button>
		</div>

		 <div class="layui-form-item" style="text-align: center;margin-top: 15px;">
			<button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="submitForm" style="width: 300px;">提交</button>
		</div>
</form>
    <!-- layui.js -->
    <script src="/static/layui/layui.js"></script>
      <script src="/static/layui/layui.all.js"></script>
<script type="text/javascript">

		layui.use('form', function() {
			var form = layui.form;
	
			//获取验证码监听
			form.on('submit(sendEmail)', function(data) {
				//layer.msg(JSON.stringify(data.field));
                var email = data.field.email;
                $("#yzmbtn").attr({"disabled":"disabled"});
                layer.msg('请稍等！');
                $.post("/user/sendEmail",{email:email},function(result){
                    if(result.success){
                        layer.msg("验证码已发送到您的邮箱，请注意查收，假如长时间未收到邮件，请联系管理员！", {
                            icon: 1,
                            time: 5000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                        	$("#yzm").focus();
                        });
                    }else{
                        layer.msg(result.errorInfo, {
                            icon: 5,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            $("#yzmbtn").removeAttr("disabled");
                        });
                    }
                },"json");
				return false;
			});

            //提交监听
            form.on('submit(submitForm)', function(data) {
                //layer.msg(JSON.stringify(data.field));
                var yzm=$("#yzm").val();
                if(yzm==""){
                    layer.msg('请输入验证码！');
                    $("#yzm").focus();
                    return false;
                }
                $.post("/user/checkYzm",{yzm:yzm},function(result){
                    if(result.success){
                        layer.msg("已通过验证，密码已经重置成123456，请登录后立刻修改密码！", {
                            icon: 1,
                            time: 3000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                        	parent.window.location.reload();
                        });
                    }else{
                        layer.msg(result.errorInfo, {icon: 5});
                    }
                },"json");
                return false;
            });

		});
		
</script>
	
</body>
</html>